<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="批次号" prop="batchNo">
        <el-input
          v-model="queryParams.batchNo"
          placeholder="请输入批次号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="渠道名称" prop="tradeQudao">
        <el-input
          v-model="queryParams.tradeQudao"
          placeholder="请输入渠道名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

        <el-form-item label="交易结果">
          <el-select v-model="queryParams.tradeResult" placeholder="请选择交易结果">
            <el-option label="处理中" value="1"></el-option>
            <el-option label="成功" value="2"></el-option>
            <el-option label="失败" value="3"></el-option>
          </el-select>
        </el-form-item>

      <el-form-item label="交易金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入交易金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易日期" prop="tradeDateZf">
        <el-input
          v-model="queryParams.tradeDateZf"
          placeholder="请输入交易日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>



        <el-form-item label="支付方式">
          <el-select v-model="queryParams.payWay" placeholder="请选择支付方式">
            <el-option label="微信扫码" value="1"></el-option>
            <el-option label="支付宝扫码" value="2"></el-option>
            <el-option label="微信公众号" value="3"></el-option>
            <el-option label="认证支付" value="4"></el-option>
            <el-option label="代付到银行卡" value="5"></el-option>
          </el-select>
        </el-form-item>




        <el-form-item label="差错处理结果">
          <el-select v-model="queryParams.processState" placeholder="请选择差错处理结果">
            <el-option label="未处理" value="1"></el-option>
            <el-option label="要结算" value="2"></el-option>
            <el-option label="不结算" value="3"></el-option>
            <el-option label="已处理" value="4"></el-option>
          </el-select>
        </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="批次号" align="center" prop="batchNo" />
      <el-table-column label="交易流水号" align="center" prop="payOrderNo" />
      <el-table-column label="渠道订单号" align="center" prop="qudaoOrderNo" />
      <el-table-column label="渠道名称" align="center" prop="tradeQudao" />
      <el-table-column label="交易结果" align="center" prop="tradeResult" >
        <template slot-scope="scope">
              <span v-if="scope.row.tradeResult==1">
               处理中
              </span>
          <span v-if="scope.row.tradeResult==2">
                成功
              </span>
          <span v-if="scope.row.tradeResult==3">
                失败
              </span>

        </template>
      </el-table-column>
      <el-table-column label="交易金额" align="center" prop="amount" />
      <el-table-column label="交易日期" align="center" prop="tradeDateZf" />
      <el-table-column label="手续费" align="center" prop="commissionFee" />
      <el-table-column label="支付方式" align="center" prop="payWay" >
        <template slot-scope="scope">
              <span v-if="scope.row.payWay==1">
               微信扫码
              </span>
          <span v-if="scope.row.payWay==2">
                支付宝扫码
              </span>
          <span v-if="scope.row.payWay==3">
                微信公众号
              </span>
          <span v-if="scope.row.payWay==4">
                认证支付
              </span>
          <span v-if="scope.row.payWay==5">
                代付到银行卡
              </span>
        </template>
      </el-table-column>
      <el-table-column label="交易账户" align="center" prop="tradeAccount" />
      <el-table-column label="交易账户类型" align="center" prop="tradeAccountType" >
        <template slot-scope="scope">
              <span v-if="scope.row.tradeAccountType==1">
               微信
              </span>
          <span v-if="scope.row.tradeAccountType==2">
                支付宝
              </span>
          <span v-if="scope.row.tradeAccountType==3">
                银行卡
              </span>
          <span v-if="scope.row.tradeAccountType==4">
                拉卡拉
              </span>
        </template>
      </el-table-column>
      <el-table-column label="对账完成时间：对账记录的创建时间" align="center" prop="checkEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否差错" align="center" prop="hasDiff" >
        <template slot-scope="scope">
              <span v-if="scope.row.hasDiff==1">
               否
              </span>
          <span v-if="scope.row.hasDiff==2">
                是
              </span>

        </template>
      </el-table-column>
      <el-table-column label="差错处理结果" align="center" prop="processState" >
        <template slot-scope="scope">
              <span v-if="scope.row.processState==1">
              未处理
              </span>
          <span v-if="scope.row.processState==2">
                要结算
              </span>
          <span v-if="scope.row.processState==3">
               不结算
              </span>
          <span v-if="scope.row.processState==4">
              已处理
              </span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:detail:edit']"
            v-if="scope.row.hasDiff!=1"
          >差错处理</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改对账批次明细（保存对账结果明细的）对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDetail, getDetail, delDetail, addDetail, updateDetail } from "@/api/financial/detail";

export default {
  name: "Detail",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 对账批次明细（保存对账结果明细的）表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        billDay: null,
        checkDay: null,
        batchId: null,
        batchNo: null,
        payOrderNo: null,
        qudaoOrderNo: null,
        tradeQudao: null,
        certificateJz: null,
        certificateDz: null,
        tradeResult: null,
        amount: null,
        tradeDateZf: null,
        commissionFee: null,
        payWay: null,
        tradeAccount: null,
        tradeAccountType: null,
        checkEndDate: null,
        hasDiff: null,
        processState: null,
        completeState: null,
        confirmDate: null,
        canClearingAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        billDay: [
          { required: true, message: "账期年月日不能为空", trigger: "blur" }
        ],
        checkDay: [
          { required: true, message: "对账年月日(yyyymmdd)不能为空", trigger: "blur" }
        ],
        batchId: [
          { required: true, message: "批次ID不能为空", trigger: "blur" }
        ],
        batchNo: [
          { required: true, message: "批次号不能为空", trigger: "blur" }
        ],
        amount: [
          { required: true, message: "交易金额：支付订单金额不能为空", trigger: "blur" }
        ],
        payWay: [
          { required: true, message: "支付方式,同流水里面一样 1:微信扫码，2:支付宝扫码，3:微信公众号，4:认证支付，5:代付到银行卡不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询对账批次明细（保存对账结果明细的）列表 */
    getList() {
      this.loading = true;
      listDetail(this.queryParams).then(response => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        billDay: null,
        checkDay: null,
        batchId: null,
        batchNo: null,
        payOrderNo: null,
        qudaoOrderNo: null,
        tradeQudao: null,
        certificateJz: null,
        certificateDz: null,
        tradeResult: null,
        amount: null,
        tradeDateZf: null,
        commissionFee: null,
        payWay: null,
        tradeAccount: null,
        tradeAccountType: null,
        checkEndDate: null,
        hasDiff: null,
        processState: null,
        completeState: null,
        confirmDate: null,
        canClearingAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加对账批次明细（保存对账结果明细的）";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "您确是否要进行差错处理?";
      });
    },
    /** 提交按钮 */
    submitForm() {

    this.form.hasDiff=1;
    this.form.processState=4;
            updateDetail(this.form).then(response => {
              this.msgSuccess("处理成功");
              this.open = false;
              this.getList();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除对账批次明细（保存对账结果明细的）编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDetail(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/detail/export', {
        ...this.queryParams
      }, `system_detail.xlsx`)
    }
  }
};
</script>
